module.exports = {
  getRateX(x, w) {
    return parseInt(x * (device.width / (w || device.width)));
  },
  getRateY(y, h) {
    return parseInt(y * (device.height / (h || device.height)));
  },
  clickXY(x, y) {
    click(x, y);
  },
  clickXYZW(x, y, z, w, deltaX, deltaY) {
    var maxDeltaX = Math.abs(z - x) / 2;
    var maxDeltaY = Math.abs(w - y) / 2;
    deltaX = deltaX || 1;
    deltaY = deltaY || 1;
    deltaX = deltaX > maxDeltaX ? maxDeltaX - 2 : deltaX;
    deltaY = deltaY > maxDeltaY ? maxDeltaY - 2 : deltaY;
    this.clickXY(
      random(x + deltaX, z - deltaX),
      random(y + deltaY, w - deltaY)
    );
  },
  clickBounds(bounds, deltaX, deltaY) {
    var left = bounds.left;
    var right = bounds.right;
    var top = bounds.top;
    var bottom = bounds.bottom;
    this.clickXYZW(left, top, right, bottom, deltaX, deltaY);
  },
  clickPointMap(pointMap, deltaX, deltaY) {
    var point = pointMap[0];
    var width = pointMap[1];
    var height = pointMap[2];
    var x = this.getRateX(point[0], width);
    var y = this.getRateY(point[1], height);
    var z = this.getRateX(point[2], width);
    var w = this.getRateY(point[3], height);
    this.clickXYZW(x, y, z, w, deltaX, deltaY);
  },
  clickTextUI(TextUI, deltaX, deltaY) {
    this.clickBounds(TextUI.bounds(), deltaX, deltaY);
  },
  clickTextOCR(TextOCR, deltaX, deltaY) {
    this.clickBounds(TextOCR.bounds, deltaX, deltaY);
  },
};
